package com.witmed.mymdm.ui.home


import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.recyclerview.widget.GridLayoutManager
import androidx.recyclerview.widget.RecyclerView
import com.example.quickadapter.BaseQuickMultipleAdapter
import com.example.quickadapter.BaseViewHolder
import com.witmed.mymdm.R

class HomeAdapter():
    BaseQuickMultipleAdapter<HomeEntity, BaseViewHolder>() {

    override fun convert(holder: BaseViewHolder, item: HomeEntity) {
        when(item.getType()){
            1->{
                holder.setText(R.id.tv1,item.title)
                holder.setImage(R.id.iv1,item.icon)
            }
            2->{
                holder.setText(R.id.tv2,item.title)
                holder.setImage(R.id.iv2,item.icon)
            }
        }
    }

    override fun getMultiSpanSize(position: Int, recyclerView: RecyclerView): Int {
        val manager = recyclerView.layoutManager
        if(manager !is GridLayoutManager){
            return 1
        }
        if(data[position].getType()==1){
            return 3
        }
        return 1
    }

    override fun createItemView(viewType: Int, parent: ViewGroup): View {
       if(viewType==1){
            return LayoutInflater.from(parent.context).inflate(R.layout.home_item1,parent,false)
        }else{
           return LayoutInflater.from(parent.context).inflate(R.layout.home_item2,parent,false)
       }
    }

    override fun getItemViewType(position: Int): Int {
        return data[position].getType()
    }


}